/*
 * @Description:
 * @Author: chenju
 * @Date: 2022-03-22 15:19:19
 * @LastEditors: chenju
 * @LastEditTime: 2022-12-07 18:05:27
 */
import { get, post } from '@/utils/http'
import type {
  GetTaskListParams,
  GetTaskListResult,
  GetTaskInfoResult,
  GetTaskListMatchResult,
  PostTaskCreateParams,
  GetOrgTreeByInventoryYearResult,
  TaskDetailChildTaskItem,
  PostTaskAccountParams
} from './model/inventoryTaskModel'
import type { BasicPagingListParams, BasicPagingListResult } from '@/apis/basicModel'

enum Api {
  // 任务列表
  GET_TASK_LIST = '/inventory/task/pageTask',
  // 查询子任务列表
  GET_SUB_TASK_LIST = '/inventory/task/listChildTask',
  // 查询任务详情
  GET_TASK_INFO = '/inventory/task/getTaskInfo',
  // 关联填报任务列表
  GET_TASK_LIST_MATCH = '/inventory/task/listMatchFillTask',
  // 创建任务
  POST_TASK_CREATE = '/inventory/task/createTask',
  // 编辑任务
  POST_TASK_EDIT = '/inventory/task/editTask',
  // 获取年度组织树
  GET_ORG_TREE = '/inventory/organization/getOrganizationTree',
  // 获取任务树
  GET_TASK_TREE = '/inventory/task/getChildTree',
  // 核算任务
  POST_TASK_ACCOUNT = '/inventory/task/accountTask',
  // 删除盘查任务
  POST_DELETE_TASK = '/inventory/task/deleteTask'
}

// 任务列表
export const getTaskList = (
  params: GetTaskListParams & BasicPagingListParams
): Promise<BasicPagingListResult<GetTaskListResult>> => get(Api.GET_TASK_LIST, params)

// 查询任务详情
export const getTaskInfo = (taskNo: string): Promise<GetTaskInfoResult> =>
  get(Api.GET_TASK_INFO, { taskNo })

// 关联填报任务列表
export const getTaskListMatch = (taskNo: string): Promise<GetTaskListMatchResult[]> =>
  get(Api.GET_TASK_LIST_MATCH, { taskNo })

// 新建任务
export const postTaskCreate = (params: PostTaskCreateParams): Promise<void> =>
  post(Api.POST_TASK_CREATE, params)

// 编辑任务
export const postTaskEdit = (params: PostTaskCreateParams): Promise<void> =>
  post(Api.POST_TASK_EDIT, params)

// 获取年度组织树（获取年度组织树）
export const getOrgTreeByInventoryYear = (
  inventoryYear: string
): Promise<GetOrgTreeByInventoryYearResult[]> => get(Api.GET_ORG_TREE, { inventoryYear })

/**
 * 获取任务树
 * @param taskNo
 * @returns
 */
export const getTaskTree = (taskNo: string): Promise<TaskDetailChildTaskItem[]> =>
  get(Api.GET_TASK_TREE, { taskNo })

/**
 * 核算任务
 * @param params
 * @returns
 */
export const postTaskAccount = (params: PostTaskAccountParams): Promise<void> =>
  post(Api.POST_TASK_ACCOUNT, params)

/**
 * 删除盘查任务
 */
export const postDeleteTask = (taskNo: string): Promise<void> =>
  post(Api.POST_DELETE_TASK, { taskNo })
